package com.to.aboomy.bannersample.slice;

import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.IndicatorView;
import com.to.aboomy.bannersample.ResourceTable;
import com.to.aboomy.bannersample.adapter.BannerAdapter;
import com.to.aboomy.bannersample.bean.BannerBean;
import com.to.aboomy.bannersample.bean.TextBean;
import com.to.aboomy.bannersample.util.Utils;
import com.to.aboomy.bannersample.viewpager.creator.ImageHolderCreator;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.utils.Color;

import java.util.ArrayList;
import java.util.List;

public class RecyclerAbilitySlice extends AbilitySlice {
    private ListContainer list;
    private Button update;
    BannerAdapter bannerAdapter;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_recycler);

        list = (ListContainer) findComponentById(ResourceTable.Id_list);
        update = (Button) findComponentById(ResourceTable.Id_update);
        bannerAdapter = new BannerAdapter(this);

        loadData();
        list.setItemProvider(bannerAdapter);

        Component inflate = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_item_view_banner, null, false);;
        Text textView = (Text) inflate.findComponentById(ResourceTable.Id_text);
        textView.setText("我是被addHeaderView添加进来的");
        Banner banner = (Banner) inflate.findComponentById(ResourceTable.Id_banner);
        banner.setHolderCreator(new ImageHolderCreator());
        banner.setIndicator(new IndicatorView(this).setIndicatorColor(Color.GRAY).setIndicatorSelectorColor(Color.WHITE));
        banner.setPages(Utils.getImage(4));
        bannerAdapter.addHeaderView(inflate);
    }

    private void loadData(){
        List<Object> list = new ArrayList<>();
        BannerBean bannerBean = new BannerBean();
        bannerBean.urls = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            bannerBean.urls.add(Utils.getRandomImage());
        }
        list.add(bannerBean);
        for (int i = 0; i < 100; i++) {
            TextBean textBean = new TextBean();
            textBean.text = "--- " + i;
            list.add(textBean);
        }
        bannerAdapter.setData(list);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
